<template>
  <div>
<h1>用户理财</h1>
<table>
  <tr>
    <td>理财名称</td>
    <td>{{listss.LC_Name}}</td>
  </tr>
  <tr>
    <td>年收益</td>
    <td>{{listss.LC_ShouYi}}</td>
    </tr>
  <tr>
    <td>利息</td>
    <td>
      <select v-model="listss.L_Id">
        <option value="0">请选择</option>
        <option :value="item.L_Id" v-for="item in list">{{item.L_Number*100}}%</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>最低金额</td>
    <td>{{listss.LC_Money}}</td>
  </tr>
  <tr>
    <td>风险等级</td>
    <td>
      <select v-model="listss.F_Id">
        <option value="0">请选择</option>
        <option :value="item.F_Id" v-for="item in lists">{{item.F_Name}}</option>
      </select>
    </td>
  </tr>
  <tr>
    <td>理财金额</td>
    <td><input type="text" v-model="UL_Money"></td>
  </tr>
  <tr>
    <td></td>
    <td><input type="button" value="增加理财" @click="ok"></td>
  </tr>
</table>
  </div>
</template>

<script setup lang="ts">
import {reactive,toRefs,onMounted} from 'vue'
import axios from 'axios'
import {useRoute,useRouter} from 'vue-router'
const router=useRouter()
const route=useRoute()

let data:any=reactive({
  state:{},
  UL_Money:'',
  list:[],
  lists:[],
  listss:[]
})

let {state,list,lists,UL_Money,listss}=toRefs(data)

onMounted(()=>{
  getData()
  getDate()
  getList()
})

const getList=()=>{
axios({
  url:'/api/LiCai/GetFanTian',
  method:'get',
  params:{
    LC_Id:route.query.LC_Id,
  }
})
.then(res=>{
  console.log(res);
  listss.value=res.data.data
})
}

const getData=()=>{
  axios({
    url:'/api/LiCai/XiaLa1',
    method:'get'
  })
  .then(res=>{
    console.log(res.data);
    list.value=res.data.data
  })
}

const getDate=()=>{
  axios({
    url:'/api/LiCai/XiaLa2',
    method:'get'
  })
  .then(res=>{
    console.log(res.data);
    lists.value=res.data.data
  })
}

const ok=()=>{
  axios({
    url:'/api/LiCai/AddUserLiCai',
    method:'post',
    data:{
      LC_Id:route.query.LC_Id,
      UL_Money:UL_Money.value
    }
  })
  .then(res=>{
    if(res.data.data==-1){
      alert('理财名称已存在');
      return;
    }
    else{
      alert('添加理财成功');
      router.push('/licaiShow');
    }
  })
}
</script>

<style scoped>

</style>